package com.fita.admin.entity.search.data;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;

import java.util.Map;

/**
 * 
 * @author dan
 *
 */
public class CitySearch implements QueryBuilder {

    private String chineseName;

    private String englishName;

    private String code;

    private String postalCode;

    private String countryCode;

    private QueryFilter queryFilter;

    private QueryOrder queryOrder;

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {

        if (queryFilter == null || refresh) {

            queryFilter = new QueryFilter();

            queryFilter.addLike("chineseName", chineseName)
                       .addLike("englishName", englishName)
                       .addLike("code", code)
                       .addLike("postalCode", postalCode)
                       .addEquals("countryCode", countryCode);

        }

        return queryFilter;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public QueryOrder getOrder() {
        if (queryOrder == null) {
            queryOrder = new QueryOrder();
        }
        return queryOrder;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        return "FROM City WHERE disabled = false " + getPreparedFilter(false).clauseSentence();
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }

    /**
     * @return the queryFilter
     */
    public QueryFilter getQueryFilter() {
        return this.queryFilter;
    }

    /**
     * @return the queryOrder
     */
    public QueryOrder getQueryOrder() {
        return this.queryOrder;
    }

    /**
     * 
     * @return
     */
    public String getChineseName() {
        return chineseName;
    }

    /**
     * 
     * @return
     */
    public String getCode() {
        return code;
    }

    /**
     * 
     * @return
     */
    public String getPostalCode() {
        return postalCode;
    }

    /**
     * 
     * @return
     */
    public String getCountryCode() {
        return countryCode;
    }

    /**
     * 
     * @return
     */
    public String getEnglishName() {
        return englishName;
    }

    /**
     * @param queryFilter the queryFilter to set
     */
    public void setQueryFilter(QueryFilter queryFilter) {
        this.queryFilter = queryFilter;
    }

    /**
     * @param queryOrder the queryOrder to set
     */
    public void setQueryOrder(QueryOrder queryOrder) {
        this.queryOrder = queryOrder;
    }

    /**
     * 
     * @param chineseName
     */
    public void setChineseName(String chineseName) {
        this.chineseName = chineseName;
    }

    /**
     * 
     * @param englishName
     */
    public void setEnglishName(String englishName) {
        this.englishName = englishName;
    }

    /**
     * 
     * @param code
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * 
     * @param postalCode
     */
    public void setPostalCode(String postalCode) {
        this.postalCode = postalCode;
    }

    /**
     * 
     * @param countryCode
     */
    public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    }

}